/***
MASTER
Date: July 2022
Author: IM

Master do file for the paper Foreign Shocks as Granular Fluctuations

***/

* Install needed packages
ssc install gtools
ssc install winsor2
ssc install winsor, replace
ssc install reghdfe, replace
ssc install ftools, replace

** Set up global paths (where the data is stored)
global dopath "C:\Users\Public\Documents\DoFiles\doFiles_TransmissionModel\Submission"
global datapath "C:\Users\Public\Documents\MICRONA_M_ISABELL\Documents\Temp_Comovements"

* output
global outputpath "C:\Users\Public\Documents\Results_TransmissionModel"
global outputpathcsv "C:\Users\Public\Documents\Results_TransmissionModel\CSV"
global outputpathpdfs "C:\Users\Public\Documents\Results_TransmissionModel\PDF"
global datacsvmatlab "C:\Users\Public\Documents\DoFiles\doFiles_TransmissionModel\Matlab\CES\CSV"

* Balance sheet data
global commonpath "C:\Users\Public\Documents\Data\Brn"
global brnpath "C:\Users\Public\Documents\Data\Brn"
global ficuspath "C:\Users\Public\Documents\Data\ficus"
global farepath "C:\Users\Public\Documents\Data\fare"

* Customs data
global source "\\casd.fr\casdfs\Projets\MICRONA\Import\20200722_01\import Dynam"
global sourcepath "C:\Users\Public\Documents\Data\Customs"
global dofiles "C:\Users\Public\Documents\DoFiles\do files customs data"
global rawpathcm "\\casd.fr\casdfs\Projets\MICRONA\Import\20200722_01\import Dynam\ClassiqueMensuel"
global rawpathcur "\\casd.fr\casdfs\Projets\MICRONA\Import\20200722_01\import Dynam\ImpExpDevise2011_17"
global rawpathdeb "\\casd.fr\casdfs\Projets\MICRONA\Import\20200722_01\import Dynam\Import DEB"
global rawbuyer "\\casd.fr\casdfs\Projets\MICRONA\Import\20200722_01\import Dynam\Preprocess"
global datapathCustoms "C:\Users\Public\Documents\Data\Customs"

* Lifi data
global data_lifi "C:\Users\Public\Documents\Data\lifi"
global codes_country "\\casd\casdfs\LibreAcces\Nomenclatures géographiques\Codes géographiques\Codes officiels géographiques (Insee.fr)"
global final_data "C:\Users\Public\Documents\Data\lifi\pierre_04_2022_HQ_filiale_iso"
global datapathLifi "C:\Users\Public\Documents\Data\lifi\pierre_04_2022_HQ_filiale_iso"


* Other data
global otherdatapath "C:\Users\Public\Documents\Data"
global graphpath "C:\Users\Public\Documents\Results\StatDes"
global macrodatapath "C:\Users\Public\Documents\Entrees\20160414\DataCASD\MacroData"
global datapathother "C:\Users\Public\Documents\Data\Data_TransmissionModel"
global wiotdata "C:\Users\Public\Documents\Data\Data_TransmissionModel"



** Set up global for time, sector and country spans
global firstyearbrn=1993
global lastyearbrn=2007
global firstyearcustoms=1993
global lastyearcustoms=2007
global variable vabcf
global thresholdFR = "2"
global firstyear = "1990"
global lastyear = "2007"
global year = "2006"
global yearactual = "2005"
global allyears = "1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007"
global sect = "naf60"
global wiotcountry = "AUS AUT BEL BGR BRA CAN CHN CYP CZE DEU DNK ESP EST FIN GBR GRC HUN IDN IND IRL ITA JPN KOR LTU LVA MEX MLT NLD POL PRT ROU RUS ROW SVK SVN SWE TUR TWN USA"
global wiotcountry_FRA = "AUS AUT BEL BGR BRA CAN CHN CYP CZE DEU DNK ESP EST FIN GBR GRC HUN IDN IND IRL ITA JPN KOR LTU LVA MEX MLT NLD POL PRT ROU RUS ROW SVK SVN SWE TUR TWN USA FRA"
global regcountries = "AUS AUT BEL BGR BRA CAN CHN CYP CZE DEU DNK ESP EST FIN GBR GRC HUN IDN IND IRL ITA JPN KOR LTU LVA MEX MLT NLD POL PRT ROU RUS SVK SVN SWE TUR USA"
global wiotsector = "AtB 15t16 C 17t18 19 20 21t22 23 24 25 26 27t28 29 30t33 34t35 36t37"
global wiotsector_ALLXJP = "AtB 15t16 C 17t18 19 20 21t22 23 24 25 26 27t28 29 30t33 34t35 36t37 E F 50 51 52 H 60 61 62 63 64 70 71t74 M N O"
global wiotsector_NT_Only = "50 51 52 N M 70 64 63 62 61 60 H F E 71t74 O"
global wiotsector_High_Merch = "50 51 52"
global wiotsector_ordered = "AtB C 15t16 17t18 19 20 21t22 23 24 25 26 27t28 29 30t33 34t35 36t37 E F 50 51 52 H 60 61 62 63 64 70 71t74 M N O"
global wiotcountry_prices = "AUS AUT BEL BGR CAN CHN CZE DEU DNK ESP FIN GBR GRC HUN IRL ITA JPN KOR LTU MEX NLD POL PRT ROU RUS ROW SVN SWE TWN USA FRA"
global Manufacturing = "17t18 19 20 21t22 23 24 25 26 27t28 29 30t33 34t35 36t37 "
global Services = "F N M 70 64 63 62 61 60 H 52 51 50 71t74 O"
global Mining = "C"
global Energy = "E"
global Food = "AtB 15t16"

global input $datapath/brn_$firstyearbrn$lastyearbrn
global sample brn
global method 2

** Run our do files
do "$dopath/01_0_balancesheet_customs.do"
do "$dopath/02_0_Firm_Level.do"
do "$dopath/03_0_WIOT.do"
do "$dopath/04_0_Calibration.do"
do "$dopath/05_0_VA_GDP_Trade.do"
do "$dopath/06_0_Export_CSV.do"
do "$dopath/07_0_Lifi.do"
do "$dopath/08_0_Motivational_Regressions.do"


